<template>
  <div>
    <el-form :inline="false" class="m-form" ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item class="m-form-item" label="请假时长" prop="f_day">
        <el-input-number :readonly="viewer" v-model="form.f_day" :precision="1" :step="0.5" :min="0.5" :max="100"></el-input-number>
      </el-form-item>
      <el-form-item class="m-form-item" label="开始时间" prop="f_startTime">
        <el-date-picker
          :readonly="viewer"
          v-model="form.f_startTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item class="m-form-item" label="结束时间" prop="f_endTime">
        <el-date-picker
          :readonly="viewer"
          v-model="form.f_endTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item class="m-form-item" label="请假事由" prop="f_reason">
        <el-input
          :readonly="viewer"
          type="textarea"
          :rows="2"
          placeholder="请输入请假事由"
          v-model="form.f_reason">
        </el-input></el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: 'LeaveForm',
  props: {
    value: {
      type: Object,
      default() {
        return {}
      }
    },
    viewer: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      form: {
        f_day: 1,
        f_reason: '',
        f_startTime: '',
        f_endTime: ''
      },
      rules: {
        f_day: [
          { required: true, message: '请假时长不能为空', trigger: 'blur' }
        ],
        f_reason: [
          { required: true, message: '请假事由不能为空', trigger: 'blur' }
        ],
        f_startTime: [
          { required: true, message: '开始时间不能为空', trigger: 'blur' }
        ],
        f_endTime: [
          { required: true, message: '结束时间不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  watch: {
    value: {
      handler(n) {
        this.form = n
      },
      deep: true
    }
  },
  methods: {
    validate(callback) {
      return this.$refs['form'].validate(callback)
    },
    resetFields() {
      this.$refs['form'].resetFields()
      this.$refs['form'].clearValidate()
    }
  }
}
</script>
